home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Complementary Applications 2004 May / SGI IRIX 6.5 Complementary Applications 2004 May.iso / dist / OpenOffice.idb / usr / OpenOffice / help / en / sbasic.jar / text / sbasic / common / 03090101.xml < prev    next >
Encoding:
Extensible Markup Language  |  2002-01-24  |  5.0 KB  |  61 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <html><head><title>If...Then...Else Statement [Runtime]</title><meta name="filename" content="text/sbasic/common/03090101"/><meta name="language" content="en-US"/><help:css-file-link xmlns:help="http://openoffice.org/2000/help"/><!--The CSS style header method for setting styles--><style type="text/css">
  3.  
  4.         table.Tabelle1{
  5.                 }
  6.         span.Tabelle1A{
  7.                 width:1.499cm;}
  8.         span.Tabelle1B{
  9.                 width:16.498cm;}
  10.         tr.Tabelle11{
  11.                 }
  12.         td.Tabelle1A1{
  13.                 }
  14.         p.P1{
  15.                 }
  16.         p.P2{
  17.                 }
  18.         span.T1{
  19.                 font-weight:bold;}
  20.         span.fr1{
  21.                 }
  22.         </style></head><body>
  23.   
  24.   
  25.   <help:to-be-embedded Eid="ifthenelse" xmlns:help="http://openoffice.org/2000/help">
  26.   <p class="Head1"><help:link Id="66523">If...Then...Else Statement [Runtime]</help:link></p>
  27.   <p class="Paragraph">Defines one or more statement blocks to be executed only if a given condition is True.</p>
  28.   </help:to-be-embedded>
  29.   <p class="Paragraph"><span class="T1">Syntax</span>:</p>
  30.   <p class="Paragraph">If condition=true Then Statementblock [ElseIf condition=true Then] Statementblock [Else] Statementblock End If <help:key-word value="If" tag="kw66523_1" xmlns:help="http://openoffice.org/2000/help"/></p>
  31.   <p class="Paragraph"><span class="T1">Parameter</span>:</p>
  32.   <p class="Paragraph">The <span class="T1">If...Then</span> statement is used to execute program blocks depending on given conditions. When <help:productname xmlns:help="http://openoffice.org/2000/help">%PRODUCTNAME</help:productname> Basic encounters an <span class="T1">If</span> statement, the condition is tested. If True, all subsequent statements up to the next <span class="T1">Else</span> or <span class="T1">ElseIf</span> statement are executed. If the condition is False, and an <span class="T1">ElseIf</span> statement follows, <help:productname xmlns:help="http://openoffice.org/2000/help">%PRODUCTNAME</help:productname> Basic tests the next condition and executes the following statements if the condition is True. If False, the program continues either with the next <span class="T1">ElseIf</span> or <span class="T1">Else</span> <text:s text:c="" xmlns:text="http://openoffice.org/2000/text"/>statement. Statements following <span class="T1">Else</span> are executed only if none of the previously tested conditions were True. After all conditions have been evaluated, and the corresponding statements executed, the program continues with the statement following <span class="T1">EndIf</span>.</p>
  33.   <p class="Paragraph">Multiple <span class="T1">If...Then</span> statements may be nested.</p>
  34.   <p class="Paragraph"><span class="T1">Else</span> and <span class="T1">ElseIf</span> statements are optional.</p>
  35.   <table><tr class="Tabelle11"><th class="Tabelle1A1" style="text-align:left;"><span class="Tabelle1A">
  36.       <p class="TextInTable"><draw:image draw:style-name="fr1" draw:name="HIND_1" text:anchor-type="paragraph" svg:width="0.847cm" svg:height="0.847cm" draw:z-index="0" xlink:href="65640" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" draw:filter-name="GIF - Graphics Interchange" xmlns:draw="http://openoffice.org/2000/drawing" xmlns:text="http://openoffice.org/2000/text" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"/></p>
  37.      </span></th><th class="Tabelle1A1" style="text-align:left;"><span class="Tabelle1B">
  38.       <p class="TextInTable">You can use <span class="T1">GoTo</span> and <span class="T1">GoSub</span> to jump out of an <span class="T1">If...Then</span> block, but not to jump into an <span class="T1">If...Then</span> structure.</p>
  39.      </span></th></tr></table>
  40.   <p class="Paragraph"/>
  41.   <p class="Paragraph">The following example enables you to enter the expiration date of a product, and returns whether the expiration date has passed.</p>
  42.   <p class="P2">Example:</p>
  43.   <p class="PropText">Sub ExampleIfThenDate</p>
  44.   <p class="PropText">Dim sDate as String</p>
  45.   <p class="PropText">Dim sToday as String</p>
  46.   <p class="PropText"/>
  47.   <p class="PropText">sDate = InputBox("Enter the expiration date (MM.DD.YYYY)")</p>
  48.   <p class="PropText">sDate = Right$(sDate, 4) + <text:s text:c="" xmlns:text="http://openoffice.org/2000/text"/>Mid$(sDate, 4, 2) <text:s text:c="" xmlns:text="http://openoffice.org/2000/text"/>+ Left$(sDate, 2)</p>
  49.   <p class="PropText">sToday = Date$</p>
  50.   <p class="PropText">sToday = Right$(sToday, 4)+ <text:s text:c="2" xmlns:text="http://openoffice.org/2000/text"/>Mid$(sToday, 4, 2) <text:s text:c="" xmlns:text="http://openoffice.org/2000/text"/>+ Left$(sToday, 2)</p>
  51.   <p class="PropText">If sDate < sToday Then</p>
  52.   <p class="PropText">MsgBox "The expiration date has passed"</p>
  53.   <p class="PropText">ElseIf sDate > sToday Then</p>
  54.   <p class="PropText">MsgBox "The expiration date has not yet passed"</p>
  55.   <p class="PropText">Else</p>
  56.   <p class="PropText">MsgBox "The expiration date is today"</p>
  57.   <p class="PropText">End If</p>
  58.   <p class="PropText"/>
  59.   <p class="PropText">End Sub</p>
  60.   <p class="PropText"/>
  61.  </body></html>